(function($) {

    var types = ['DOMMouseScroll', 'mousewheel'];

    if ($.event.fixHooks) {
        for ( var i=types.length; i; ) {
            $.event.fixHooks[ types[--i] ] = $.event.mouseHooks;
        }
    }

    $.event.special.mousewheel = {
        setup: function() {
            if ( this.addEventListener ) {
                for ( var i=types.length; i; ) {
                    this.addEventListener( types[--i], handler, false );
                }
            } else {
                this.onmousewheel = handler;
            }
        },

        teardown: function() {
            if ( this.removeEventListener ) {
                for ( var i=types.length; i; ) {
                    this.removeEventListener( types[--i], handler, false );
                }
            } else {
                this.onmousewheel = null;
            }
        }
    };

    $.fn.extend({
        mousewheel: function(fn) {
            return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
        },

        unmousewheel: function(fn) {
            return this.unbind("mousewheel", fn);
        }
    });


    function handler(event) {
        var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
        event = $.event.fix(orgEvent);
        event.type = "mousewheel";

        // Old school scrollwheel delta
        if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta/120; }
        if ( orgEvent.detail     ) { delta = -orgEvent.detail/3; }

        // New school multidimensional scroll (touchpads) deltas
        deltaY = delta;

        // Gecko
        if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
            deltaY = 0;
            deltaX = -1*delta;
        }

        // Webkit
        if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
        if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }

        // Add event and delta to the front of the arguments
        args.unshift(event, delta, deltaX, deltaY);

        return ($.event.dispatch || $.event.handle).apply(this, args);
    }

})(jQuery);

/*admin - module_navs.js*/
$(document).ready(function(){
    var arrWidth = [];
    var sl = 3, i = 0, temp = 0,arrTemp = [], flag, qty, max, length, maxWidth, maxVitri = 0, minVitri, position, catId, catCom;
    var ajax_request;
    var nav = $('#navigation');
    var bouns_nav = $('.bouns_nav');
    var navLi = nav.children('li');
    var navWrap = $('.navigation-wrapper');

    navLi.each(function(){
        if(i == 0){
            arrWidth[i++] = $(this).width();
        }
        else
        {
            arrWidth[i] = $(this).width() + arrWidth[--i];
            i = i + 2;
        }
    });

    length = navLi.length;
    maxWidth = arrWidth[length-1];

    for(i = length - 1; length > 0 ; i--  )
    {
        temp = maxWidth - arrWidth[i];
        if(temp <= 950)
            maxVitri = i;
        else
            break;
    }

    for(i = 0; i < length; i++ )
    {
        if(arrWidth[i] <= 950)
            minVitri = i;
        else
            break;
    }

    if (arrWidth[length - 1] > 950) {

        navWrap.append('<a class="nav-prev" href="#"></a> <a class="nav-next invi" href="#"></a>');
        i = 0;

        function NavPrev(event) {
            var qty = event.data;
            var flag = i + qty ;

            flag = flag > maxVitri ? maxVitri : flag;

            if (flag < length) {
                i = flag;
                $('.nav-next').removeClass('invi');
                nav.stop().animate({
                    'marginLeft':-arrWidth[i]
                }, 500);
            }

            if(flag == maxVitri)
            {
                $('.nav-prev').addClass('invi');
            }
        }

        function NavNext(event) {

            if (i >= 0) {
                qty = event.data;
                flag = i + qty;

                if (flag < minVitri) {
                    if(i==0)
                        $('.nav-prev').removeClass('invi');
                    i = 0;
                    $('.nav-next').addClass('invi');
                    nav.stop().animate({
                        'marginLeft':0
                    }, 500);
                }
                else {
                    i = flag;
                    $('.nav-prev').removeClass('invi');
                    nav.stop().animate({
                        'marginLeft':-arrWidth[i]
                    }, 500);
                }
            }
        }

        $('.nav-prev').click(sl, function (event) {
            NavPrev(event);
            return false;
        });

        $('.nav-next').click(-sl, function (event) {
            NavNext(event);
            return false;
        });

        navWrap.mousewheel(function (event, delta) {
            if (delta > 0)
                $('.nav-next').trigger('click');
            else if (delta < 0)
                $('.nav-prev').trigger('click');
            return false;
        });

        nav.find('li').hover(function() {
            /*In
            temp = $(this).attr('class');
            arrTemp = temp.split('_');
            position = $(this).position();
            bouns_nav.css({ left:position.left, top:'100%'});
            if(typeof(ajax_request) != 'undefined')
                ajax_request.abort();

            ajax_request = $.ajax({
                type  :'POST',
                url     : url_base,
                data    : {'flag': 1 ,'catID':arrTemp[0], 'catCom':arrTemp[1]},
                dataType: 'html',
                success:function(data){

                }
            });

        }, function(){
           Out*/
        });
    }
});